#include <bits/stdc++.h>
const int NN = 20000 + 4;
using namespace std;
int N, MaxS, Centroid;
vector<int> G[NN];
int dfs(int u, int fa) {
  int s = 1, max_s = -1;
  for (int v : G[u]) {
    if (v == fa) continue;
    int sv = dfs(v, u);
    s += sv, max_s = max(max_s, sv);
  }
  max_s = max(max_s, N - s);
  if (max_s < MaxS || (max_s == MaxS && Centroid > u))
    MaxS = max_s, Centroid = u;
  return s;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    cin >> N;
    for (int i = 1; i <= N; i++) G[i].clear();
    for (int i = 1, u, v; i < N; i++)
      cin >> u >> v, G[u].push_back(v), G[v].push_back(u);
    MaxS = NN, Centroid = 0, dfs(1, -1);
    printf("%d %d\n", Centroid, MaxS);
  }
  return 0;
}
